#ifndef CPP_SYSTEM_CONTROLLER_H
#define CPP_SYSTEM_CONTROLLER_H

class Timer;

//@brief 系统控制
//@author cvte
//@description 系统控制器
class SystemController {
   public:
    class SystemControllerListener {
       public:
        virtual void onSysDateTimeChanged(); //日期时间改变
    };

    friend class IPC;

    static const int KSWAP_DEFAULT_VALUE = 1019;  //交换分区触发阈值
    static SystemController* getInstance();

    //@method 双缓冲临时保持打开，直到完成一次绘制，目前用于Activity跳转
    static void setDoubleBufferKeepEnableBeforePaintFinish();
    static void setDoubleBufferAllowDisable(bool allow);
    static bool getDoubleBufferAllowDisable();
    static void doubleBufferEnable(bool enable);
    static bool isDoubleBufferEnabled();
    static void slideBufferEnable(bool enable);
    static bool isSlideBufferEnabled();
    //@method 设置背光0 ～ 100
    static void setBrightness(int brightness);
    //@method 获取背光0 ～ 100
    static int getBrightness();
    static bool recovery();
    //@method 设置KSWAP的触发值
    static void setKswap(int value);
    //@method 释放caches
    static void freeCaches(void);
    //@method 通过system函数执行命令
    static void runCommand(const char *cmd);
    //@method 发送Power Key
    static void sendPowerKey(void);
    //@method 清空屏幕显示
    static void clearScreen();
    //@method 同步网络时间（NTP）
    static void syncNetworkTime();

    //@method 设置系统状态控制监听器
    void setListener(SystemControllerListener& listener);
    //@method 设置系统时区，默认+8时区
    void setTimezone(int timezone);
    //@method 设置系统日期与时间
    bool setDateTime(unsigned int year, unsigned int mon, unsigned day, unsigned int hour, unsigned min, unsigned int sec);

   protected:
    //@method 网络时间更新通知处理，通过listener回调
    void networkTimeUpdateNotifyProc();

   private:
    static SystemController* sInstance;
    static bool mIsDoubleBufferAllowDisable;
    static bool mIsDoubleBufferEnabled;
    static bool mIsSlideBufferEnabled;
    static Timer mRecoveryTimer;

    SystemControllerListener* mListener = nullptr;
    int mTimezone = 8; //默认+8时区

    SystemController();
    ~SystemController();
};

#endif